<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="/plugins/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="/css/global.css" media="all">
    <link rel="stylesheet" href="/plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="/css/table.css"/>
    <title>币种管理</title>
    <style type="text/css">
        .searcheBottom{margin-bottom: 10px;}
        body{overflow-y: scroll;}
    </style>
</head>
<body class="admin-main">
<blockquote class="layui-elem-quote">
    <div class="demoTable">
        <div class="layui-inline searcheBottom">
            中文名称：
            <div class="layui-inline">
                <input id="coinNameCn" class="layui-input" name="coinNameCn" autocomplete="off" placeholder="币种中文名称"/>
            </div>
        </div>
        <div class="layui-inline searcheBottom">
            英文名称：
            <div class="layui-inline">
                <input id="coinNameEn" class="layui-input" name="coinNameEn" autocomplete="off" placeholder="币种英文名称"/>
            </div>
        </div>
        <div class="layui-inline searcheBottom">
            简称：
            <div class="layui-inline">
                <input id="symbol" class="layui-input" name="symbol" autocomplete="off" placeholder="币种简称"/>
            </div>
        </div>
        <div class="layui-inline searcheBottom">
            货币诊断：
            <div class="layui-inline">
                <select  id="currencyDiagnosisFlag" name="currencyDiagnosisFlag" class="layui-input" style="padding: 0px 20px;">
                    <option value="">全部</option>
                    <option value="1">支持</option>
                    <option value="0">不支持</option>
                </select>
            </div>
        </div>
        <div class="layui-inline searcheBottom">
            状态：
            <div class="layui-inline">
                <select  id="enableFlag" name="enableFlag" class="layui-input" style="padding: 0px 20px;">
                    <option value="">请选择状态</option>
                    <option value="1">使用中</option>
                    <option value="0">已下架</option>
                </select>
            </div>
        </div>
        <div class="layui-inline searcheBottom">
            <button class="layui-btn" data-type="reload" id="search" >搜索</button>
            <a class="layui-btn layui-btn-primary" id="reset">重置</a>
            <a data-opt="add" href="/manage/currency/addcur" class="layui-btn" id="addReport"><i class="layui-icon">&#xe608;</i>添加货币</a>
        </div>
    </div>
</blockquote>
<span style="font-size: 16px;"><b>货币列表</b></span>
<table class="layui-hide" id="currencyTable" lay-filter="tableFilter"></table>
</div>
<script type="text/javascript" src="/plugins/layui/layui.js"></script>
<script>
    layui.use(['jquery','table','laydate','layer','form','util'],function(){
        var $=layui.jquery,table=layui.table,laydate = layui.laydate,
            layer = layui.layer,form = layui.form,util=layui.util;

        pageInit();
        //表格渲染
        function pageInit(){
        	table.render({
                elem:"#currencyTable",
                url:"/manage/currency/listCurrency",
                method:"post",
                cols:[[
                    {field:'id', title: 'ID', sort: true,align:'center'},
                    {field:'coinNameCn', title: '名称',align:'center',templet: function(d){
                    	return d.coinNameCn+"/"+d.coinNameEn;
                    }},
/*                    {field:'', title: '所属行业',align:'center',templet: function(d){
                   	   if(d.currencyIndustryList!=null && d.currencyIndustryList.length>0){
                   		   var hy="";
                   		   for(var i=0;i< d.currencyIndustryList.length;i++){
                   			 hy+=d.currencyIndustryList[i].industryName;
                   			 if(i+1 < d.currencyIndustryList.length){
                   			     hy+=",";
                             }
                   		   }
                		return hy;
                	 }else{
                		 return '';
                	 }  
                     }},*/
/*                    {field:'', title: '所属概念',align:'center',templet: function(d){
                      	 if(d.currencyConceptList!=null && d.currencyConceptList.length>0){
                      		 var gn="";
                     		   for(var i=0;i< d.currencyConceptList.length;i++){
                     			  gn+=d.currencyConceptList[i].conceptName;
                                   if(i+1 < d.currencyIndustryList.length){
                                       gn+=",";
                                   }
                     		   }
                  		return gn;
                   	 }else{
                   		 return '';
                   	 }
                    } },*/
                    {field:'currencyDiagnosisFlag', title: '货币诊断', align:'center',
                        templet:function(d){
                            if(d.currencyDiagnosisFlag==true){
                                return '<div class="layui-btn layui-bg-green layui-btn-xs">支持</div>'
                            }else if(d.currencyDiagnosisFlag==false){
                                return '<div class="layui-btn layui-bg-gray layui-btn-xs">不支持</div>'
                            }else{
                                return '';
                            }
                        }
                    },
                    {field:'weights', title: '权重货币', align:'center',
                        templet:function(d){
                            if(d.weights==true){
                                return '<div class="layui-btn layui-bg-green layui-btn-xs">支持</div>'
                            }else if(d.weights==false){
                                return '<div class="layui-btn layui-bg-gray layui-btn-xs">不支持</div>'
                            }else{
                                return '';
                            }
                        }
                    },
                    {field:'frenchCurrency', title: '法币', align:'center',
                        templet:function(d){
                            if(d.frenchCurrency==true){
                                return '<div class="layui-btn layui-bg-green layui-btn-xs">支持</div>'
                            }else{
                                return '<div class="layui-btn layui-bg-gray layui-btn-xs">不支持</div>'
                            }
                        }
                    },
                    {field:'imageUrl', title: '图标',align:'center',templet:function(d){
                   	 return '<div><img style="width: 50px;height: 50px;" src="'+d.imageUrl+'"></div>'
                    }},
                    {field:'enableFlag', title: '状态',align:'center',
                        templet:function(d){
                            if(d.enableFlag==true){
                                return '<div class="layui-btn layui-bg-green layui-btn-xs">使用中</div>'
                            }else if(d.enableFlag==false){
                                return '<div class="layui-btn layui-bg-gray layui-btn-xs">已下架</div>'
                            }else{
                                return '';
                            }
                        }},
                    {field:'updateTime', title: '修改时间',align:'center',sort:true,
                        templet: function(d){
                        	if(d.updateTime!=null){
                        		return util.toDateString(d.updateTime, 'yyyy-MM-dd HH:mm:ss');
                        	}else{
                        		return '';
                        	}
                            
                        }
                    },
                    {field: 'tool', title:"操作",align:'left',width:500,align:'center',
                        templet:function(d){
                            var tool = '<a href="#" class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>';
                            tool+='<a href="#" class="layui-btn layui-btn-normal layui-btn-xs" lay-event="webtra">web关联交易对</a>';
                            tool+='<a href="#" class="layui-btn layui-btn-normal layui-btn-xs" lay-event="apptra">app关联交易对</a>';
                            tool+='<a href="#" class="layui-btn layui-btn-normal layui-btn-xs" lay-event="encap">编辑概括</a>';
                            if(d.enableFlag==true){
                                tool+='<a href="#" class="layui-btn layui-btn-warm layui-btn-xs" lay-event="enable">下架</a>';
                            }else{
                                tool+='<a href="#" class="layui-btn layui-btn-normal layui-btn-xs" lay-event="enable">上架</a>';
                            }
                            tool+='<a href="#" class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>';
                            return tool;
                        }
                    }
                ]],
                limits:[10,15,20,25,30],
                limit:10,
                page:true
            });
        };
        

        var active = {
            reload: function () {
                var coinNameCn = $('#coinNameCn');
                var currencyDiagnosisFlag = $('#currencyDiagnosisFlag option:selected');
                var enableFlag = $('#enableFlag option:selected');
                table.reload('currencyTable', {
                    where: {
                        coinNameCn: coinNameCn.val(),
                        coinNameEn: coinNameEn.value,
                        symbol:symbol.value,
                        currencyDiagnosisFlag:currencyDiagnosisFlag.val(),
                        enableFlag:enableFlag.val()
                    }
                });
            }
        };

        //将搜索框的值随请求传到后台
        $('.demoTable #search').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

        $(".layui-input").keydown(function (e) {
            if(e.keyCode == 13){
                $('#search').click();
            }
        });

        //重置
        $("#reset").on("click",function(){
            coinNameCn.value = '';
            coinNameEn.value='';
            symbol.value='';
            currencyDiagnosisFlag.value = '';
            enableFlag.value = '';
        });

        //表格监听
        table.on('tool(tableFilter)', function(obj){
            var data = obj.data;
            if (obj.event == "enable") {
                $.ajax({
                    url:"/manage/currency/enableCurrency",
                    type:"post",
                    dataType:"json",
                    data:{"id":data.id,"enable_flag":data.enableFlag},
                    success:function(count){
//                        pageInit();
                        table.reload('currencyTable');
                    }
                })
            } else if (obj.event == "edit") {
            	location.href='/manage/currency/eidtCurrency?id='+data.id;
            } else if (obj.event == "del") {
                layer.confirm('是否删此行？', {icon: 7, title:'提示'},function (index) {
                	$.ajax({
        	            type : "POST",
        	            url : "/manage/currency/delCurrency",
        	            dataType : "json",
        	            data :{"id":data.id},
        	            success : function(resData) {
        	          	  layer.alert(resData.msg, {
        	          		    skin: 'layui-layer-molv' //样式类名  自定义样式
        	          		    ,closeBtn: 1    // 是否显示关闭按钮
        	          		    ,anim: 1 //动画类型
        	          		    ,btn: ['确定'] //按钮
        	          		    ,icon: 1    // icon
        	          		    ,yes:function(){
        	          		    	if (resData.code >= 0) {
        	          		    	    layer.closeAll()
                                        table.reload('currencyTable');
        	          	              }
        	          		    }});
        	            },
        	            error : function() {
        	                alert("系统异常,请稍后重试");
        	            }
        	        });
                });
            }else if(obj.event == "webtra"){
                location.href='/manage/currency/webCurTra?id='+data.id+'&coinNameCn='+data.coinNameCn+"/"+data.coinNameEn+'&symbol='+data.symbol;
            }else if(obj.event == "encap"){
                location.href='/manage/currency/addoreditlate?id='+data.id;
            }else if(obj.event == "apptra"){
                location.href='/manage/currency/appCurTra?id='+data.id+'&coinNameCn='+data.coinNameCn+"/"+data.coinNameEn+'&symbol='+data.symbol;
            }
        });
    })
</script>
</body>
</html>